package com.zktr.service;
import java.util.LinkedList;
import java.util.List;
import com.zktr.bean.BrandBean;
import com.zktr.dao.BrandDao;
import com.zktr.pojo.Brand;
import com.zktr.pojo.PageBean;
public class BrandService {

	BrandDao dao = new BrandDao();
	public static void main(String[] args) {
		Brand brand = new Brand();
		brand.setBrandname("苹果");
		brand.setBranddesc("苹果");
		brand.setBrandlogo("苹果");
		brand.setIsshow(true);
		BrandService brandService = new BrandService();
		 System.out.println(brandService.updateBrand(brand, 1));
		/*PageBean<BrandBean> queryAllBrand = brandService.queryAllBrand(1, 5);
		List<BrandBean> beanList = queryAllBrand.getBeanList();
	    for (BrandBean brandBean : beanList) {
			System.out.println(brandBean);
		}*/
		
	}
	public PageBean<BrandBean> queryAllBrand(int pc, int ps) {
		List<BrandBean> brandBean=new LinkedList<>();
		List<Brand> list = dao.queryAllBrand(pc, ps);
		findAllBrand(list,brandBean);
		PageBean<BrandBean> bean = new PageBean<BrandBean>();
		bean.setPc(pc);
		bean.setPs(ps);
		bean.setBeanList(brandBean);
		bean.setTr(dao.selectBrandCount());
		return bean;
	}
	 private static void findAllBrand(List<Brand> list, List<BrandBean> list2) {
			for (Brand brand : list) {
				BrandBean bBean = new BrandBean();
				bBean.setBrandid(brand.getBrandid()+"");
				bBean.setBrandname(brand.getBrandname());
				bBean.setBrandlogo(brand.getBrandlogo());
				bBean.setSortorder(brand.getSortorder()+"");
				bBean.setBranddesc(brand.getBranddesc());
				if (brand.getIsshow()) {
				bBean.setIsshow("../img/yes.gif");	
				}else {
				bBean.setIsshow("../img/err.gif");
				}	
				list2.add(bBean);
			}
			
	    }
		/**
		 * 查询某一类商品中存在的品牌
		 * @return 
		 */
		public List<Brand> queryBraandByCatid(int catid) {
			return dao.selectBraandByCatid(catid);
		}
		public List<Brand> queryAllBrandId(int parseInt) {
			return dao.queryAllBrandId(parseInt);
		}
		
		public int updateBrand(Brand brand,int parseInt) {
			return dao.updateBrand(brand,parseInt);
		}
		public int updateBrandlogo(Brand brand, int id) {
			return dao.updateBrandlogo(brand, id);
		}
		public int deleteOneBrandId(int id) {
			return dao.deleteOneBrandId(id);
		}
		public int addBrand(Brand brand) {
			// TODO Auto-generated method stub
			return dao.addBrand(brand);
		}
}
